using System;
using System.Reflection;
using Microsoft.EntityFrameworkCore;
using TodoList.EFCore;
using TodoList.Options;

var builder = WebApplication.CreateBuilder(args);

var section = builder.Configuration.GetSection("RedisOptions");
builder.Services.Configure<RedisOptions>(section);

builder.Services.AddAutoMapper(Assembly.GetExecutingAssembly()); 
builder.Services.AddDbContext<TodoDbContext>(options =>
{
    var connectionString = builder.Configuration.GetConnectionString("Default");
    
    options.UseNpgsql(connectionString);
    AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);
});

builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
    app.UseSwagger();
    app.UseSwaggerUI();
}

app.UseHttpsRedirection();

app.UseAuthorization();

app.MapControllers();

app.Run();
